home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Science
/
MathPad 2.1.5
/
examples
/
vector ops
< prev
next >
Wrap
Text File
|
1993-06-13
|
816b
|
25 lines
-- Arrays can be used to represent vectors. Addition, subtraction and multiplication by a scalar can be done directly. The following functions implement other basic vector operations.
dot(A,B) = sum(A[i]*B[i],i,1,count(A))
magnitude(A) = sqrt(dot(A,A))
cross(A,B) = {A[2]*B[3]-A[3]*B[2],
A[3]*B[1]-A[1]*B[3],
A[1]*B[2]-A[2]*B[1]}
-- cartesian to spherical coordinates
spherical(A) = {magnitude(A),
acos(A[3]/magnitude(A)),
atan2(A[2],A[1])}
-- spherical to cartesian coordinates
cartesian(r,theta,phi) = {r*sin(theta)*cos(phi),
r*sin(theta)*sin(phi),
r*cos(theta) }
atan2(y,x) = 0 when x=0 and y=0,
atan(y/x) when x>=0,
atan(y/x)+180 when y>=0,
atan(y/x)-180